# -*- coding: utf-8 -*-
"""
file:ch6_7定积分函数
author: Fuwen
time: 2022/7/20 7:02
software:PyCharm
"""
from sympy import *

# 被积函数 f(x) = x**2
x = Symbol('x')
f = x**2
print(integrate(f, (x, 1, 3)))

f1 = -x**2 + 2*x
print(integrate(f1, (x, -2, 4)))
# 需要分段积分，否则直接代入积分上限和下限，值会小于0

f2 = x**2 - 2*x
s1 = integrate(f2, (x, -2, 0))
s2 = integrate(f1, (x, 0, 2))
s3 = integrate(f2, (x, 2, 4))
print(s1+s2+s3)

